<?php

require_once(dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/appconf.php');

class mapi_itrial_category extends Site {

    function setup() {
        $this->run_modes('list');
        $this->start_mode('list');
        parent::setup();
    }

    function cgiapp_prerun() {
        $this->Lookup = getModel('Model_Lookup');
        $this->height = 300;
        $this->width = 300;
        parent::cgiapp_prerun();
    }

    function action_list() {
        $is_big_category = intval($this->get_q('is_big_category', 0, 'int'));
        $category_topid = intval($this->get_q('category_topid', 0, 'int'));
        $category_list_array = array();

        $url = $this->param('URL');

        $kvcobj = getCache('mapi_category_list', array('expire' => KVC_EXPIRE));
        $category_list = $kvcobj->get('mapi_category_list_' . $is_big_category . '_' . $category_topid);
        if (!$category_list) {
            if ($is_big_category || $category_topid) {
                if ($is_big_category) {
                    $h_param = array(
                        'type' => 'product_layout_category',
                    );
                } else {
                    $h_param = array(
                        'type' => 'product_layout_category',
                        'topid' => $category_topid,
                    );
                }
            } else {
                $h_param = array(
                    'type' => 'product_layout_category_all',
                );
            }
            $category_list = $this->Lookup->h_get_lookup($h_param);
            $kvcobj->set('mapi_category_list_' . $is_big_category . '_' . $category_topid, $category_list);
        }

        if ($category_list['result'])
            $category_list_array = $category_list['result'];

        if ($category_list_array) {
            foreach ($category_list_array as $key => $value) {


                $value['icon_url'] = $url . $value['m_icon_image2'];
                unset($value['m_icon_image2']);
                $category_list_array[$key] = $value;
            }
            $this->ajaxReturn($category_list_array, array('retcode' => '1', 'msg' => 'ok'));
        } else {
            $this->ajaxReturn(array(), array('retcode' => '0', 'msg' => 'not ok'));
        }
    }

}

header("Content-type: text/html; charset=utf-8");
$webapp = new mapi_itrial_category();
$webapp->run();
?>